<?php
class TeacherProfilesController extends AppController {
    var $name =  'TeacherProfiles';
        
    function edit($id = null) {
        $this->pageTitle = "修改资料";
        $this->TeacherProfile->id = $id;
        if (($this->Auth->user('id') == $this->TeacherProfile->field('user_id')) || ($this->Auth->user('role') == 'admin')) {
            if (!$this->data) {
                $this->data = $this->TeacherProfile->read();
            }
            else {
                $this->TeacherProfile->save($this->data);
                $this->Session->setFlash("资料修改成功");
                if ($this->Auth->user('role') == 'admin') {
                    $this->redirect(array('controller' => 'users', 'action' => 'add'));
                }
                else {
                    $this->redirect(array('controller' => 'teacher_profiles', 'action' => 'index'));
                }
            }
        }
        else {
            $this->Session->setFlash("您没有相应的权限");
            $this->redirect(array('controller' => 'users', 'action' => 'login'));
        }
    }
    
    function index() {
        $this->pageTitle = "教师管理面板";
        if ($this->Auth->user('role') == 'teacher') {
            $this->set('my_info', $this->TeacherProfile->findByUserId($this->Auth->user('id')));
        }
        else {
            $this->Session->setFlash("您没有相应的权限");
            $this->redirect(array('controller' => 'users', 'action' => 'login'));
        }
    }
}
?>
